#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;
short count(int year)
{
    stringstream ss;
    ss << right << setw(4) << setfill('0') <<year;
    string s;
    ss >> s;
    bool ifSee[10] = {};
    for(int i = 0; i<10; i++)
        ifSee[i] = false;
    for(int i = 0; i<s.length(); i++)
        ifSee[s[i]-'0'] = true;
    int sum  = 0;
    for(int i = 0; i< 10; i++)
    {
        if(ifSee[i] == true)
            sum = sum + 1;
    }
    return sum;
        
}
int main()
{
    int x;
    int n;
    cin >> x >> n;
    
    for(int i = x; i<=9999; i++)
    {
        if(count(i) == n)
        {
            cout <<i - x << " " << setw(4)<< setfill('0') << i;
            break;
        }
    }
}